#pragma once

#ifdef PF_PLATFORM_PC

namespace pf
{
	class InputKeyboardPC : public InputKeyboard
	{
	public:

		void Initialise()
		{
			memset(m_keyStateCur, 0, sizeof(KeyboardButtonState::Enum)*KeyboardButton::Key_NumberOf);
			memset(m_keyStatePrev, 0, sizeof(KeyboardButtonState::Enum)*KeyboardButton::Key_NumberOf);
		}

		void Step()
		{
			memcpy(m_keyStatePrev, m_keyStateCur, sizeof(KeyboardButtonState::Enum)*KeyboardButton::Key_NumberOf);
		}

		void SetKeyUp(WPARAM key)
		{
			m_keyStateCur[RemapWParam(key)] = KeyboardButtonState::KeyState_Up;
		}

		void SetKeyDown(WPARAM key)
		{
			m_keyStateCur[RemapWParam(key)] = KeyboardButtonState::KeyState_Down;
		}

		bool GetKeyPressed(KeyboardButton::Enum key)
		{
			return (m_keyStateCur[key] == KeyboardButtonState::KeyState_Down) && (m_keyStatePrev[key] == KeyboardButtonState::KeyState_Up);
		}

		bool GetKeyDown(KeyboardButton::Enum key)
		{
			return (m_keyStateCur[key] == KeyboardButtonState::KeyState_Down);
		}

		bool GetKeyUp(KeyboardButton::Enum key)
		{
			return (m_keyStateCur[key] == KeyboardButtonState::KeyState_Up);
		}

	private:

		KeyboardButtonState::Enum	m_keyStateCur[KeyboardButton::Key_NumberOf];
		KeyboardButtonState::Enum	m_keyStatePrev[KeyboardButton::Key_NumberOf];

		KeyboardButton::Enum RemapWParam(WPARAM wparam)
		{
			if (wparam >= 0x30 && wparam <= 0x39)
			{
				return (KeyboardButton::Enum)(KeyboardButton::Key_0 + (wparam - 0x30));
			}
			else if (wparam >= 0x41 && wparam <= 0x5A)
			{
				return (KeyboardButton::Enum)(KeyboardButton::Key_A + (wparam - 0x41));
			}
			else if (wparam >= VK_NUMPAD0 && wparam <= VK_NUMPAD9)
			{
				return (KeyboardButton::Enum)(KeyboardButton::Key_Numpad0 + (wparam - VK_NUMPAD0));
			}
			else if (wparam == VK_SPACE)
			{
				return KeyboardButton::Key_Space;
			}
			else
			{
				return KeyboardButton::Key_Unknown;
			}
		}
	};
}

#endif // PF_PLATFORM_PC